import { createPinia } from 'pinia'
import { markRaw } from 'vue'
import { message } from 'ant-design-vue';
import httpAxios from '@/api/http-axios.js';
import { createPersistedState } from 'pinia-plugin-persistedstate'

const pinia = createPinia();
 
function apiPlugin({ store, app }) {
	httpAxios.configuration({
		loading: (isOpen) => {
			if(isOpen){
				app.config.globalProperties.$Loading.show();
			} else {
				app.config.globalProperties.$Loading.close();
			}
		},
		before: (object) => {
			
		},
		after:()=>{
			
		}
	})
	return {$Http:markRaw(httpAxios)}//使用markRaw标记为非响应式。即httpAxios 对象不会转为响应式
}

pinia.use(apiPlugin);

pinia.use(({ store, app }) => {
	store.$Message = message;//挂载 ant-design-vue 全局组件
	store.$Loading = app.config.globalProperties.$Loading;
})

pinia.use(
	createPersistedState({
		key: (id) => `_d_${id}`,
		auto: false,
	})
);

export default pinia